let grad = {
    name:'zhangyansong',
    school:'hubei',
    score:100,
    password:'******'
}

let hander ={
    //读
    get(target,prop){
        if(prop.startsWith("_")){
            throw new Error('不能读取私有属性')
        }
        else {
            return target[prop]
        }
    },
    //写
    set(target,prop,value){
        if (prop.startsWith("_")) {
            throw new Error('不能给私有属性设置值')
        }
        else {
            target[prop] = value
        }
    },
    //遍历
    ownKeys(target){
        Reflect.ownKeys(target).filter(key=>key.startsWith('_'))
    }，
    //删除
    deleteProperty(target,prop){
        if(prop.startsWith('_') && Reflect.has(target,prop)){
            throw new Error('不可删除')
            return true
        }
        else if(prop in target){
            delete target[prop]
        }
        else {
            throw new Error('此属性不存在')
        }
    }
}
grade = new Proxy(grade, handler)

//读操作，针对读拦截器
console.log(grade.name)
try {
    console.log(grade._password)
}
catch (e) {
    console.log(e.message)
}
//写操作
grade.name = '李四'
try{
    grade._password = '123'
}
catch{}

//遍历操作
for(let key in grade){
    console.log(key)
}
Reflect.ownKeys(grade).forEach(val=>console.log(val))

//删除操作
delete grade.name 
console.log(grade)

try{delete grade._password}
catch{}